<?php

	if($_POST)
	{
		createXML($_POST);
	}
	$xml = simplexml_load_file('../../one/xml/web-data.xml');
	$smarty->_assign(array('xml'));
	$smarty->_display();

	function createXML($data)
	{
		$xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
		$xml .= '<note>'."\n";//根节点创建
		foreach($data as $key=>$val)
		{
			if(is_array($val))
			{
				$xml .= '<'.$key.'>'."\n";
				foreach($val as $k=>$v)
				{					
					if(is_int($k))
					{
						if($k>0)$xml .= '</'.$key.'>'."\n".'<'.$key.'>'."\n";
						foreach($v as $kk=>$vv)
						{								
							$xml .= '<'.$kk.'>'.$vv.'</'.$kk.'>'."\n";								
						}						
					}else{					
						if(is_array($v))
						{
							foreach($v as $kk=>$vv)
							{
								$xml .= '<'.$k.'>'.$vv.'</'.$k.'>'."\n";
							}
						}else{
							$xml .= '<'.$k.'>'.$v.'</'.$k.'>'."\n";
						}						
					}
				}
				$xml .= '</'.$key.'>'."\n";		
			}else{
				$xml .= '<'.$key.'>'.$val.'</'.$key.'>'."\n";
			}
		}
		$xml .= '</note>';//根节点闭合
		$fp = fopen('../../one/xml/web-data.xml', "w"); //打开要写入 XML数据的文件
		fwrite($fp, $xml); //写入 XML数据
		fclose($fp); //关闭文件 
	}
?>